package com.dqx.haoqiu.mvp.common.dagger;

import android.content.Context;

import com.dqx.haoqiu.repository.api.NewsApi;
import com.dqx.haoqiu.repository.api.UserApi;
import com.dqx.haoqiu.mvp.common.config.AppConfig;
import com.dqx.haoqiu.repository.db.DataBase;
import com.dqx.haoqiu.repository.db.NewsDao;
import com.xmjs.baselibrary.network.retrofit.RetrofitUtil;
import com.xmjs.baselibrary.utils.SP;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;

@Module
public class AppModule {
    private Context context;

    @Provides
    public Context provideContext() {
        return this.context;
    }

    public AppModule(Context context) {
        this.context = context;
    }

    @Singleton
    @Provides
    public SP provideSP(Context context) {
        return new SP(context);
    }

    @Singleton
    @Provides
    public UserApi provideUserApi(SP sp) {
        return RetrofitUtil.getService(UserApi.class, AppConfig.API_BASE_URL, sp);
    }

    @Singleton
    @Provides
    public NewsApi provideNewsApi(SP sp) {
        return RetrofitUtil.getService(NewsApi.class, AppConfig.API_BASE_URL, sp);
    }

    @Singleton
    @Provides
    public NewsDao provideNewsDao() {
        return DataBase.getInstance(context).getNewsDao();
    }
}
